package com.beordie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.beordie.dao.CategoryDao;
import com.beordie.dao.SellerDao;
import com.beordie.model.Category;
import com.beordie.model.Seller;
import com.beordie.service.ICategoryService;
import com.beordie.service.ISellerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description
 * @Date 2021/8/5 16:38
 * @Created 30500
 */
@Service
public class CategoryServiceImpl implements ICategoryService {
    @Autowired
    private CategoryDao categoryDao;

    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public PageInfo<Category> findPage(int pageNum, int pageSize) {
        QueryWrapper<Category> wrapper = new QueryWrapper<>();
        PageHelper.startPage(pageNum, pageSize);
        List<Category> sellerList = categoryDao.selectList(wrapper);
        return new PageInfo<>(sellerList);
    }

    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public List<Category> find() {
        QueryWrapper<Category> wrapper = new QueryWrapper<>();
        List<Category> sellerList = categoryDao.selectList(wrapper);
        return sellerList;
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int add(Category category) {
        return categoryDao.insert(category);
    }

    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public Category findById(Integer id) {
        return categoryDao.selectById(id);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int update(Category category) {
        return categoryDao.updateById(category);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int delete(Integer id) {
        return categoryDao.deleteById(id);
    }
}
